package com.nisum.mocksimulator.webservice;

import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.nisum.mocksimulator.webservice.beans.CarType;

@Component
public class CarWebServiceClient {
	@Value("http://localhost:9191/ws/car?wsdl")
	private URL url;
	
	public CarType getCarFromWebService(String name, int year) {
		try {
			url = new URL("http://localhost:9191/ws/car?wsdl");		
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}

	    QName qname = new QName("http://webservice.mocksimulator.nisum.com/", "CarWebServiceImplService");

	    Service service = Service.create(url, qname);

	    CarWebService ws = service.getPort(CarWebService.class);
	    
	    CarType ct = ws.getCar(name, year);

		return ct;
	}
}
